package org.fessingapore.library.controllers;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.fessingapore.library.constants.ItemType;
import org.fessingapore.library.constants.Language;
import org.fessingapore.library.models.Group;
import org.fessingapore.library.models.Item;
import org.fessingapore.library.models.Loan;
import org.fessingapore.library.models.Member;
import org.fessingapore.library.services.GroupService;
import org.fessingapore.library.services.ItemService;
import org.fessingapore.library.services.LoanService;
import org.fessingapore.library.services.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/loan")
public class LoanController {

	private MemberService memberService;
	private ItemService itemService;
	private LoanService loanService;
	
	@Autowired
	public void setMemberService(MemberService memberService) {
		this.memberService = memberService;
	}
	
	@Autowired
	public void setItemService(ItemService itemService) {
		this.itemService = itemService;
	}

	@Autowired
	public void setLoanService(LoanService loanService) {
		this.loanService = loanService;
	}
	
	@RequestMapping(value = "", method = RequestMethod.POST)
	public String addLoan(Loan loan, Model model) {
		Member member = memberService.getById(loan.getMember().getId());
		Item item = itemService.getById(loan.getItem().getId());
		loan.setItem(item);
		loan.setMember(member);
		loanService.borrowItem(loan);
		return "redirect:/group";
	}

	
}
